$(function(){
        //显示编辑真爱理念弹框
        $('.ni-pushConcept,.deanpublish,.ideaBtn').off('click').on('click',function(){
            var _this = $(this);
            var isLogin = _this.attr('is_login');
            if (isLogin == '' || isLogin == null) {
                $('.dr_blackwall,.ni-loginBox').fadeIn();
                loginRefresh();
                return false;
            }else{
                alertFadeIn('.actionTips');
            }
        });

        var loginRefresh = function() {
            var _this = $('.ni-loginBox');
            var requestUrl = _this.attr('request-url');
            window.loginInterval = setInterval(function() {
                $.get('/user/login', function(res) {
                    if (res.result >= 0) {
                        alertFadeOut('.ni-loginBox');
                        window.location.href=requestUrl;
                      clearInterval(window.loginInterval);
                    }
                });
            },1000);
        };

        //关闭,取消真爱理念
        $('.tipsClose,.tipsCancel').off('click').on('click',function(){
            alertFadeOut('.actionTips');
        });

        //真爱理念字数限制
        $('.boderLine').focus(function(){
            $(this).addClass('colorLine');
        }).blur(function(){
            $(this).removeClass('colorLine');
        }).keyup(function(){
            var ideaStr = $(this).val();
            var syLen = 140-ideaStr.length;
            if(syLen >= 0){
                $('.tipsInfo i').html(syLen);
            }else{
                $(this).val(ideaStr.substring(0,140));
            }
        });

         //创建真爱理念
        $('.create_love_idea').off('click').on('click',function(){
            var _this = $(this);
            $('.ts_wrong').remove();
            var postUrl = $('.post_url').val();
            var content = $('.boderLine').val();
            var isToken = _this.attr('is_token');

            if (isToken == '' || isToken == null) {
                var notice = '<em class="red ts_wrong">&nbsp;请重新登录</em>';
                $('.love_idea_content').after(notice);
                $('.love_idea_content').addClass('error');
                return false;
            }

            if (content == '') {
                var notice = '<em class="red ts_wrong">&nbsp;内容不为空</em>';
                $('.love_idea_content').after(notice);
                $('.love_idea_content').addClass('error');
                return false;
            }
            if (content.length < 3) {
                var notice = '<em class="red ts_wrong">&nbsp;字数不够</em>';
                $('.love_idea_content').after(notice);
                $('.love_idea_content').addClass('error');
                return false;
            }
            if (!isNumberOr_Letters(content)) {
                var notice = '<em class="red ts_wrong">&nbsp;内容格式不对</em>';
                $('.love_idea_content').after(notice);
                $('.love_idea_content').addClass('error');
                return false;
            }
            var dataTime = _this.attr('data-time');
            if (dataTime > 0) {
                var notice = $('.error_info').val();
                var notice = '<em class="red ts_wrong">&nbsp;'+notice+'</em>';
                $('.love_idea_content').after(notice);
                $('.love_idea_content').addClass('error');
                _this.attr('disabled','false');
                return false;
            }
            if (dataTime < 1) {
                _this.attr('data-time',1);
                _this.attr('disabled','false');
                $.post(postUrl,{'content':content},function(res){
                    if ( res.result >= 0 ) {
                        window.location.reload();
                    }
                    if ( res.result < 0 ) {
                        var notice = '<em class="red ts_wrong">&nbsp;'+res.message+'</em>';
                        $('.love_idea_content').after(notice);
                        $('.love_idea_content').addClass('error');
                        $('.error_info').val(res.message);
                        return false;
                    }
                });
            }
        });

    //真爱理念点赞  //首页
    $('.drIdeaLikeNum').each(function(index){
        var _this = $(this);
        _this.find('a.ni-conceptLike').off('click').on('click',function(){
            var praiseShow = $(this).attr('praise_show');
            if (praiseShow) {
                hideActionTips();
                return false;
            }
            var isLogin = $(this).attr('is_login');
            if (isLogin == '' || isLogin == null) {
                $('.dr_blackwall,.ni-loginBox').fadeIn();
                loginRefresh();
                return false;
            }
            var postUrl = $(this).attr('post_url');
            var loveId = $(this).attr('love_id');
            $.post(postUrl,{'id':loveId},function(res){
                var iStr = _this.find('.likeNum');
                var num = parseInt(iStr.html());
                if (res.result >= 0) {
                    iStr.next().addClass('ni-conceptLikeing');
                    iStr.html(num+1);
                }
                if (res.result < 0) {
                    iStr.next().removeClass('ni-conceptLikeing');
                    iStr.html(num-1);
                }
            });
        });
    });

    //真爱理念点赞   列表页
    $('.drIdeaLikeNum').each(function(index){
        var _this = $(this);
        _this.find('a.drLike').off('click').on('click',function(){
            var praiseShow = $(this).attr('praise_show');
            if (praiseShow) {
                hideActionTips();
                return false;
            }
            var isLogin = $(this).attr('is_login');
            if (isLogin == '' || isLogin == null) {
                $('.dr_blackwall').show();
                $('.zone_dltc').show();
                return false;
            }
            var postUrl = $(this).attr('post_url');
            var loveId = $(this).attr('love_id');
            $.post(postUrl,{'id':loveId},function(res){
                var iStr = _this.find('.likeNum');
                var num = parseInt(iStr.html());
                if (res.result >= 0) {
                    iStr.next().addClass('likeing');
                    iStr.html(num+1);
                }
                if (res.result < 0) {
                    iStr.next().removeClass('likeing');
                    iStr.html(num-1);
                }
            });
        });
    });


    $('.idea_more').off('click').on('click',function(){
        var _this = $(this);
        var isLogin = _this.attr('is_login');
        if (isLogin == '' || isLogin == null) {
            $('#idea_more_login').val(true);
            $('.dr_blackwall,.ni-loginBox').fadeIn();
            loginRefresh();
            return false;
        }

        var requestUrl = _this.attr('request_url');
        window.open(requestUrl);
    });

    $('.myIdeaDelete').off('click').on('click',function(){
        var _this = $(this);
        var id = _this.attr('idea_id');
        var userId = _this.attr('user_id');
        var postUrl = _this.attr('post_url');

        removeObj = _this.parents('li')[0];
        $('.dialogBox').show();
        $('.highlight').click(function(){
            $.post(postUrl,{"id":id,"user_id":userId},function(res){
            });
        });
    });

    function hideActionTips(){
        $('.dr_blackwall,.actionTips').fadeOut()
    }
});